﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Caifu.Datas;

namespace Caifu.Clients
{
	/// <summary>
	/// 基金净值操作类。
	/// </summary>
	public static class NetValueClient
	{
		/// <summary>
		/// 添加净值。
		/// </summary>
		/// <param name="netValue"></param>
		public static void AddNetValue(NetValue netValue)
		{
			NetValueData.Instance
				.AddNetValue(netValue);
		}

		/// <summary>
		/// 修改净值。
		/// </summary>
		/// <param name="netValue"></param>
		public static void UpdateNetValue(NetValue netValue)
		{
			NetValueData.Instance
				.UpdateNetValue(netValue);
		}

		/// <summary>
		/// 删除净值。
		/// </summary>
		/// <param name="id"></param>
		public static void DeleteNetValue(Guid id)
		{
			NetValueData.Instance
				.DeleteNetValue(id);
		}

		/// <summary>
		/// 获取净值。
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public static NetValue GetNetValue(Guid id)
		{
			return NetValueData.Instance
				.GetNetValue(id);
		}

		/// <summary>
		/// 获取净值。
		/// </summary>
		/// <param name="pageIndex"></param>
		/// <param name="pageSize"></param>
		/// <returns></returns>
		public static IList<NetValue> GetNetValues(Int32 pageIndex, Int32 pageSize)
		{
			return NetValueData.Instance
				.GetNetValues(pageIndex, pageSize);
		}

		/// <summary>
		/// 获取净值。
		/// </summary>
		/// <param name="fundId"></param>
		/// <param name="pageIndex"></param>
		/// <param name="pageSize"></param>
		/// <returns></returns>
		public static IList<NetValue> GetNetValues(Guid fundId, Int32 pageIndex, Int32 pageSize)
		{
			return NetValueData.Instance
				.GetNetValues(fundId, pageIndex, pageSize);
		}

		/// <summary>
		/// 获取净值。
		/// </summary>
		/// <param name="fundCode"></param>
		/// <param name="pageIndex"></param>
		/// <param name="pageSize"></param>
		/// <returns></returns>
		public static IList<NetValue> GetNetValues(string fundCode, Int32 pageIndex, Int32 pageSize)
		{
			var fund = FundClient.GetFund(fundCode);
			if (fund == null) return new List<NetValue>();

			return NetValueData.Instance
				.GetNetValues(fund.Id, pageIndex, pageSize);
		}

		/// <summary>
		/// 获取净值。
		/// </summary>
		/// <param name="reportDate"></param>
		/// <param name="pageIndex"></param>
		/// <param name="pageSize"></param>
		/// <returns></returns>
		public static IList<NetValue> GetNetValues(DateTime reportDate, Int32 pageIndex, Int32 pageSize)
		{
			return NetValueData.Instance
				.GetNetValues(reportDate, pageIndex, pageSize);
		}

		/// <summary>
		/// 获取净值。
		/// </summary>
		/// <param name="reportDate">净值时间</param>
		/// <returns></returns>
		public static IList<NetValue> GetNetValues(DateTime reportDate)
		{
			return GetNetValues(reportDate, 1, Int32.MaxValue);
		}
	}
}
